﻿#include "widget.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    /* 开启高 DPI 自适应 */
    QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);

    QApplication a(argc, argv);

    Widget w;

    /* 获取当前屏幕缩放比例 */
    QScreen *screen = QGuiApplication::primaryScreen();
    qreal dpi = screen->logicalDotsPerInch();
    /* Windows 默认 96 DPI */
    qreal scale = dpi / 96.0;

    int width = int(300 * scale);
    int height = int(600 * scale);

    w.resize(width, height);

    w.show();

    w.mask = new QWidget(&w);  // 父对象是 w，自动跟随 w
    w.mask->setStyleSheet("background-color: rgba(0, 0, 0, 20);"); // 半透明黑
    w.mask->setGeometry(w.rect());       // 尺寸与 w 一致
    w.mask->setAttribute(Qt::WA_TransparentForMouseEvents, false); // 捕获鼠标事件
    w.mask->raise();   // 确保在最上层
    w.mask->hide();

    return a.exec();
}
